package cn.dkk.behavior_design.responsibility.filter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author dkk
 * @date 2022/7/25
 * @desc
 */
public class FilterChain {

    private List<Filter> filterList=new ArrayList<>();
    private int index=0;

    public FilterChain addFilter(Filter filter) {
        filterList.add(filter);
        return this;
    }

    public void doFilter(String req,String res){
        if (index==filterList.size()){
            index=0;
        }else {
            Filter filter = filterList.get(index);
            index++;
            filter.doFilter(req,res,this);
        }
    }

}
